﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

using Cisoft.Booking.BLL;
using Cisoft.Booking.Model;

public partial class Business_Vote_VoteCount : WebUI.Page.BasePage
{
    private ShortMessageBO smBO = new ShortMessageBO();
    private ShortMessageMO smMO = new ShortMessageMO();

    private int VoteID = 0;

    #region 页面加载事件
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            VoteID = GetVoteID();
            lbl_show.Text = GetList();
        }
    }
    #endregion

    #region 获取传入的ID int GetRequestID()
    /// <summary>
    /// 获取传入的ID 
    /// </summary>
    private int GetVoteID()
    {
        int voteID = 0;
        if (Request.QueryString["VoteID"] != null)
        {
            voteID = Convert.ToInt32(Request.QueryString["VoteID"].ToString());
        }

        return voteID;
    }
    #endregion

    #region 返回事件
    protected void butrReset_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("VoteManage.aspx");
    }
    #endregion

    #region 获取数据 void GetList()
    /// <summary>
    /// 获取数据
    /// </summary>
    private string GetList()
    {
        DataSet ds = new VoteOptionBO().GetList(" VoteID_FK =" + VoteID);
        StringBuilder sb = new StringBuilder();
        int all = ds.Tables[0].Rows.Count;
        if (all > 0)
        {
            sb.Append("<tr><td style='text-align:left; font-size:12px;'>管理员发起了一次投票,目前已有" + AllVote(VoteID) + "人参与。</td></tr>");
            sb.Append("<tr><td style='text-align:left;'><span style='font-weight:bold;font-size:14px;'>" + new Cisoft.Booking.BLL.VoteBO().GetModel(VoteID).VoteContent + "</td></td></tr>");
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                double count = AllVote(VoteID)==0?0.0:(Convert.ToDouble(dr["VoteCount"].ToString()) / Convert.ToDouble(AllVote(VoteID)))*100;

                string str = String.Format("<tr><td style='text-align:left; font-size:14px;'>{0} &nbsp; ({1}%,{2}人)</td></tr>", dr["VoteOptionContent"].ToString(), Convert.ToInt32(count), dr["VoteCount"].ToString());
                sb.Append(str);
            }
        }
        return sb.ToString();
    }
    #endregion

    #region 计算投票总人数
    private int AllVote(int voteid)
    {
        int all = 0;
        DataSet ds = new VoteOptionBO().GetList(" voteid_fk = " + voteid);
        if (ds.Tables[0].Rows.Count > 0)
        {
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                all += int.Parse(dr["VoteCount"].ToString());
            }
        }
        return all;
    }
    #endregion
}
